package vg.services.main_manager;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import vg.services.config_manager.IConfigManager;
import vg.services.config_manager.ConfigManager;
import vg.services.data_base_manager.interfaces.IGraphDataBase;
import vg.services.data_base_manager.realization.SQLite4JavaCacheGraphDataBase;
import vg.services.graph_layout_manager.GraphLayoutManager;
import vg.services.graph_layout_manager.interfaces.IGraphLayoutManager;
import vg.services.graph_view_manager.GraphViewManager;
import vg.services.graph_view_manager.interfaces.IGraphViewManager;
import vg.services.lib_manager.LibManager;
import vg.services.log_manager.LogManager;
import vg.services.log_manager.interfaces.ILogger;
import vg.services.log_manager.interfaces.ILogManager;
import vg.services.log_manager.interfaces.IWindowMessage;
import vg.services.plugin_manager.realization.PluginParameter;
import vg.services.progress_manager.SimpleProgressManager;
import vg.services.progress_manager.interfaces.IProgressManager;
import vg.services.user_interface_manager.UserInterfaceManagerManager;

/**
 * This class contains links to all services.
 *
 * @author Timur Zolotuhin (e-mail: tzolotuhin@gmail.com)
 */
public class MainManager {
    // Core services
    public static final IConfigManager config = ConfigManager.getInstance();
    public static final LibManager libManager = LibManager.getInstance();

	// Log services
	public static final ILogManager logManager = new LogManager();
	public static final ILogger logger = logManager.getLogger();
	public static final IWindowMessage windowMessage = logManager.getWindowMessage();
	
	public static final IGraphDataBase graphDataBase = new SQLite4JavaCacheGraphDataBase();
	public static final UserInterfaceManagerManager view = new UserInterfaceManagerManager(graphDataBase, "Welcome to Visual Graph");
	public static final PluginParameter pluginParameter = new PluginParameter(graphDataBase, view);
	
	public static final IProgressManager progressManager = new SimpleProgressManager();
	public static final ExecutorService threadPool = Executors.newSingleThreadExecutor();
	public static final IGraphLayoutManager graphLayoutManager = new GraphLayoutManager();
	public static final IGraphViewManager graphViewManager = new GraphViewManager();

    // Main data
    private static boolean init = false;

    // Mutex
    private static final Object generalMutex = new Object();

    /**
     * Executes initial preparations.
     */
    public static void executeInitialPreparations() {
        synchronized (generalMutex) {
            if (init) return;

            // execute preparations
            libManager.setupAllPaths();

            init = true;
        }
    }
}
